package com.example.springmvcdemo3;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.List;

@RestController
public class RequestController {
    @RequestMapping(value = "/r1",method = RequestMethod.GET)
    public String r1(String name){
        return "收到来自"+name+"的请求";
    }
    @RequestMapping("/r2")
    public int r2(int age){
        return age;
    }
    @RequestMapping("/r3")
    public Integer r3(Integer age){
        return age;
    }
    @RequestMapping("/r4")
    public String r4(String name,Integer age){
        return "收到来自"+name+" age = "+age+" 的请求";
    }
    @RequestMapping("/r5")
    public String r5(Student student){
        return student.toString();
    }
    @RequestMapping("/r6")
    public String r6(@RequestParam(value = "name",required = false)String userName){
        return "收到来自"+userName+"的请求";
    }
    @RequestMapping("/r7")
    //接收数组
    public String r7(String[] str){
        return Arrays.toString(str);
    }
    @RequestMapping("/r8")
    //接收集合
    public String r8(@RequestParam List<Integer> list){
        return list.toString();
    }
    @RequestMapping("/r9")
    //接收json
    public String r9(@RequestBody Student student){
        return student.toString();
    }
    @RequestMapping("/r10/{name}/{age}")
    //获取url中的参数
    public String r10(@PathVariable("name")String name,@PathVariable Integer age){
        return "收到来自"+name+" age = "+age+" 的请求";
    }
    @RequestMapping("/r11")
    //获取文件
    public String r11(MultipartFile file){
        return file.getOriginalFilename();
    }
}
